/**
 * Copyright (C) 2009 Marcel Urbanek
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.urbiworx.sugar;

import java.io.Serializable;
import java.util.logging.Logger;

import org.xml.sax.Attributes;

public class SugarConfigurationEntry implements Serializable{

	
	Logger logger=Logger.getLogger("de.urbiworx.sugar");
	
	private int scope=SugarScopeHelper.NONE_SCOPE;
	private int line;
	private String filename;
	private String type;
	private String impl;
	private String implInstance;
	private String name;
	private String view;
	private boolean multiverse=false;
	private boolean client=false;
	
	public boolean isClient() {
		return client;
	}

	public void setClient(boolean client) {
		this.client = client;
	}

	public int getLine() {
		return line;
	}

	public SugarConfigurationEntry(Attributes atts,int line, String filename) {	
		setType(atts.getValue("type"));
		String scope=atts.getValue("in");
		if (SugarScopeHelper.REQUEST_SCOPE_NAME.equalsIgnoreCase(scope))
		{
			setScope(SugarScopeHelper.REQUEST_SCOPE);
		}
		else if (SugarScopeHelper.SESSION_SCOPE_NAME.equalsIgnoreCase(scope))
		{
			setScope(SugarScopeHelper.SESSION_SCOPE);
		}
		else if (SugarScopeHelper.APPLICATION_SCOPE_NAME.equalsIgnoreCase(scope))
		{
			setScope(SugarScopeHelper.APPLICATION_SCOPE);
		}
		else if (SugarScopeHelper.TWILIGHT_SCOPE_NAME.equalsIgnoreCase(scope))
		{
			setScope(SugarScopeHelper.TWILIGHT_SCOPE);
		}
		else if (scope!=null)
		{
			logger.warning("Scope "+scope+" is not supported. Please choose one of: "+SugarScopeHelper.REQUEST_SCOPE_NAME+" "+
					SugarScopeHelper.SESSION_SCOPE_NAME+" "+SugarScopeHelper.APPLICATION_SCOPE_NAME+" "+
					SugarScopeHelper.TWILIGHT_SCOPE_NAME);
		}
		setImpl(atts.getValue("to"));
		setImplInstance(atts.getValue("toInstance"));
		setName(atts.getValue("name"));
		setView(atts.getValue("view"));
		if (atts.getValue("client")!=null&&atts.getValue("client").equalsIgnoreCase("true"))
		{
			setClient(true);
		}
		if (atts.getValue("multiverse")!=null&&atts.getValue("multiverse").equalsIgnoreCase("true"))
		{
			System.out.println("true");
			setMultiverse(true);
		}
		this.line=line;
		this.filename=filename;
	}
	
	public String getFilename() {
		return filename;
	}

	public int getScope() {
		return scope;
	}
	public void setScope(int scope) {
		this.scope = scope;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	
	@Override
	public String toString() {
		String tempScope=scope==SugarScopeHelper.REQUEST_SCOPE?"request":scope==SugarScopeHelper.SESSION_SCOPE?"session":scope==SugarScopeHelper.APPLICATION_SCOPE?"application":scope==SugarScopeHelper.TWILIGHT_SCOPE?"twilight":"none";
		return tempScope+":"+type;
	}
	public void setImpl(String impl) {
		this.impl = impl;
	}
	public String getImpl() {
		return impl;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}

	public void setView(String view) {
		this.view = view;
	}

	public String getView() {
		return view;
	}

	public void setMultiverse(boolean multiverse) {
		this.multiverse = multiverse;
	}

	public boolean isMultiverse() {
		return multiverse;
	}

	public String getImplInstance() {
		return implInstance;
	}

	public void setImplInstance(String aImplInstance) {
		implInstance = aImplInstance;
	}

	
}
